local extension = Package("heroes_ev5")
extension.extensionName = "evolution"
--extension.game_modes_whitelist = {"brokenroyal_mode"}

local EV = require "packages/evolution/EV"
local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["heroes_ev5"] = "新约角色17-20",
  ["ev"] = "新约",
}

local shuangyechaji = General(extension, "ev__shuangyechaji", "ev", 4, 4, General.Female)
local yuezhiaoyi = fk.CreateViewAsSkill{
  name = "yuezhiaoyi",
  pattern = "nullification,jink",
  interaction = function()
    local names = {}
    for _, name in ipairs({"ev__jink","ev__nullification"}) do
      local card = Fk:cloneCard(name)
      if (Fk.currentResponsePattern == nil and Self:canUse(card)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card)) then
        table.insertIfNeed(names, card.name)
      end
    end
    if #names == 0 then return end
    return UI.ComboBox {choices = names}
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and not table.contains(U.getMark(Self, "@yuezhiaoyi_buff"), Fk:getCardById(to_select):getSuitString(true))
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    card:addSubcards(cards)
    return card
  end,

  enabled_at_play = Util.FalseFunc,
  enabled_at_response = function(self, player, response)
    return player:getMark("yuezhiaoyi_buff") > 0 and not response
  end,
}

local yuezhiaoyi_trigger = fk.CreateTriggerSkill{
  name = "#yuezhiaoyi_trigger",
  mute = true,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self.name) and target == player then
      return #U.getMark(player, "@yuezhiaoyi_buff") > 0 and table.contains(U.getMark(player, "@yuezhiaoyi_buff"), data.card:getSuitString(true))
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.additionalDamage = (data.additionalDamage or 0) + 1
  end,

  refresh_events = {fk.PreCardEffect, fk.AfterCardUseDeclared},
  can_refresh = function(self, event, target, player, data)
    if event == fk.PreCardEffect then
      return player:hasSkill(self) and (data.card.trueName == "slash" or data.card.type == Card.TypeTrick)
    else
      return player:hasSkill(self) and target == player and data.card.skillName == "yuezhiaoyi"
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.PreCardEffect then
      if player.id == data.to then
        room:addPlayerMark(player, "yuezhiaoyi_buff")
      else
        room:setPlayerMark(player, "yuezhiaoyi_buff", 0)
      end
    elseif event == fk.AfterCardUseDeclared then--清理无效标记
      room:setPlayerMark(player, "yuezhiaoyi_buff", 0)
      local mark = U.getMark(player, "@yuezhiaoyi_buff")
      table.insertIfNeed(mark, data.card:getSuitString(true))
      player.room:setPlayerMark(player, "@yuezhiaoyi_buff", mark)
    end
  end, 
}

local xinyuetuji = fk.CreateTriggerSkill{
  name = "xinyuetuji",
  anim_type = "control",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.trueName == "slash"
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, data, "#xinyuetuji::"..data.to) then
      self.cost_data = data.to
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local all_choices = {"xinyuetuji1", "xinyuetuji2"}
    local choices = table.simpleClone(all_choices)
    if to:isKongcheng() then table.removeOne(choices, "xinyuetuji1") end
    if to:getEquipment(Card.SubtypeArmor) == nil then table.removeOne(choices, "xinyuetuji2") end
    if #choices == 0 then return end
    local choice = room:askForChoice(player, choices, self.name, "", false, all_choices)
    local id = -1
    if choice == "xinyuetuji1" then
      id = EV.askForCardChosen(room, player, to, "hs", self.name)
    else
      id = to:getEquipment(Card.SubtypeArmor)
    end
    if id > 0 then
      room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
      local suit = Fk:getCardById(id):getSuitString(true)
      local mark = U.getMark(player, "@yuezhiaoyi_buff")
      if table.contains(mark, suit) then
        table.removeOne(mark, suit)
        room:setPlayerMark(player, "@yuezhiaoyi_buff", mark)
      end
    end
  end,
}

yuezhiaoyi:addRelatedSkill(yuezhiaoyi_trigger)
shuangyechaji:addSkill(yuezhiaoyi)
shuangyechaji:addSkill(xinyuetuji)

Fk:loadTranslationTable{
  ["ev__shuangyechaji"] = "泷夜叉姬",
  ["designer:ev__shuangyechaji"] = "次氯酸",
  ["yuezhiaoyi"] = "月之奥义",
  ["@yuezhiaoyi_buff"] = "月之奥义",
  [":yuezhiaoyi"] = "当你需要使用【闪】或【魔法禁令】抵消对你生效前的牌时，你可将一张除<font color=\"#D2042D\">{ }</font>外的牌当此牌使用，然后你为<font color=\"#D2042D\">{ }</font>里添加此牌的花色。你使用的<font color=\"#D2042D\">{ }</font>牌造成的伤害+1。",
  ["xinyuetuji"] = "新月突击",
  [":xinyuetuji"] = "当你使用【杀】指定一个目标后，你可弃置其一张手牌或其装备区内的防具牌，然后你删除<font color=\"#D2042D\">{ }</font>里与此牌相同的花色。",
  ["#xinyuetuji"] = "你可弃置%dest一张手牌或其装备区内的防具牌",
  ["xinyuetuji1"] = "弃置手牌",
  ["xinyuetuji2"] = "弃置防具牌",
}

local yuanjieshen = General(extension, "ev__yuanjieshen", "ev", 3, 3, General.Female)
local feisehuayue = fk.CreateTriggerSkill{
  name = "feisehuayue",
  anim_type = "offensive",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and EV.isFriend(player, target)
    and table.find(target:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#feisehuayue::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local unshown = table.filter(target:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
    if #unshown > 0 then
      local cards = room:askForCard(target, 1, 1, false, self.name, true, tostring(Exppattern{ id = unshown }), "#feisehuayue-shown")
      if #cards > 0 then
        EV.OpenCards(room, target, cards, self.name)
        local suit = room:getBanner("@feisehuayue")
        if suit and suit == Fk:getCardById(cards[1]):getSuitString(true) then
          local friends = table.map(table.filter(player.room:getOtherPlayers(target), function(p)
            return EV.isFriend(player, p) and not p:isKongcheng() end), Util.IdMapper)
          if #friends > 0 then
            local tar, id = room:askForChooseCardAndPlayers(target, friends, 1, 1, ".|.|.|hand", "#feisehuayue-choose", self.name, true)
            if #tar > 0 and id > 0 then
              local friend = room:getPlayerById(tar[1])
              local card = room:askForCard(friend, 1, 1, false, self.name, false, ".", "#feisehuayue-exchange")
              if #card > 0 then
                U.swapCards(room, player, target, friend, {id}, card, self.name)
                local mark = U.getMark(player, "feisehuayue-record")
                table.insertIfNeed(mark, target.id)
                table.insertIfNeed(mark, friend.id)
                room:setPlayerMark(player, "feisehuayue-record", mark)
              end
            end
          end
        end
        room:setBanner("@feisehuayue", Fk:getCardById(cards[1]):getSuitString(true))
      end
    end
  end,
}

local shenciliangyuan = fk.CreateTriggerSkill{
  name = "shenciliangyuan",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target.phase == Player.Play and player:hasSkill(self.name) and EV.isFriend(player, target)
    and player:usedSkillTimes(self.name, Player.HistoryRound) == 0
    and table.find(target:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 end)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#shenciliangyuan::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askForCardsChosen(player, target, 1, 1, {card_data = {{self.name, U.getMark(target, "@$shown")}}}, self.name)
    if #cards > 0 then
      room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
      room:recover({
        who = target,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    end
    local mark = U.getMark(player, "feisehuayue-record")
    local friends = table.filter(room.alive_players, function (p) return EV.isFriend(player, p) end)
    if table.every(friends, function (p) return table.contains(mark, p.id) end) then
      --U.gainAnExtraTurn(target, true, self.name)
      target:gainAnExtraTurn(true)
    end
  end,
}

yuanjieshen:addSkill(feisehuayue)
yuanjieshen:addSkill(shenciliangyuan)
Fk:loadTranslationTable{
  ["ev__yuanjieshen"] = "缘结神",
  ["designer:ev__yuanjieshen"] = "次氯酸",
  ["feisehuayue"] = "绯色花月",
  ["@feisehuayue"] = "绯色花月",
  [":feisehuayue"] = "回合技（终），若其为己方角色，你可令其明置一张手牌，若此牌与上一张以此法明置的牌花色相同，其可与一名己方角色各选择其自己的一张手牌，交换之。",
  ["#feisehuayue"] = "绯色花月：你可令%dest明置一张手牌",
  ["#feisehuayue-shown"] = "绯色花月：请明置一张手牌",
  ["#feisehuayue-choose"] = "绯色花月：你可以选择一张手牌和一名己方角色",
  ["#feisehuayue-exchange"] = "绯色花月：请选择一张手牌交换",
  ["shenciliangyuan"] = "神赐良缘",
  [":shenciliangyuan"] = "己方角色的出牌阶段开始时，你可弃置其一张明置手牌，令其回复1点体力；然后若己方角色均因“绯色花月”获得过牌，你令其于此回合结束后获得一个额外回合。",
  ["#shenciliangyuan"] = "你可以发动“神赐良缘”，弃置%dest一张明置手牌",
}

local chousanren = General(extension, "ev__chousanren", "ev", 4)

local choufengliudi = fk.CreateActiveSkill{
  name = "choufengliudi",
  anim_type = "offensive",
  prompt = "请选择一张手牌和一名角色",
  target_num = 1,
  card_num = 1,
  derived_piles = {"rain"},
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local id = EV.askForCardChosen(room, player, target, "hs", self.name)
    player:addToPile("rain", effect.cards, true, self.name)
    if id > 0 then
      target:addToPile("rain", id, true, self.name)
    end
    if player:isAlive() and target:isAlive() then
      room:setPlayerMark(player, "choufengliudi-turn", target.id)
      room:useVirtualCard("ev__duel", nil, target, player, self.name, true)
    end
  end,
}

local choufengliudi_trigger = fk.CreateTriggerSkill{
  name = "#choufengliudi_trigger",
  mute = true,
  events = {fk.EventPhaseStart, fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self.name) then
      if event == fk.EventPhaseStart then
        return player.phase == Player.Finish and player:getMark("choufengliudi-turn") ~= 0
      else
        return data.card and data.card.name == "ev__duel" and data.card.skillName == "choufengliudi"
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local to = room:getPlayerById(player:getMark("choufengliudi-turn"))
      if #player:getPile("rain") > 0 then
        room:moveCardTo(player:getPile("rain"), Card.PlayerHand, player, fk.ReasonJustMove, self.name, "", true)
      end
      if #to:getPile("rain") > 0 then
        room:moveCardTo(to:getPile("rain"), Card.PlayerHand, to, fk.ReasonJustMove, self.name, "", true)
      end
    else
      local cards = {}
      for _, p in ipairs(room.alive_players) do
        if #p:getPile("rain") > 0 then
          table.insertTableIfNeed(cards, p:getPile("rain"))
        end
      end
      room:moveCardTo(cards, Card.PlayerHand, target, fk.ReasonJustMove, self.name, "", true)
    end
  end,
}
choufengliudi:addRelatedSkill(choufengliudi_trigger)
chousanren:addSkill(choufengliudi)
Fk:loadTranslationTable{
  ["ev__chousanren"] = "愁伞人",
  ["designer:ev__chousanren"] = "烈火幽魂",
  ["choufengliudi"] = "愁锋六滴",
  ["rain"] = "雨",
  ["#choufengliudi_trigger"] = "愁锋六滴",
  [":choufengliudi"] = "阶段技，你可选择一名其他角色，将你与其各一张手牌移出游戏，称为“雨”，其视为对你使用【决斗】；当一名角色因执行此【决斗】的效果而造成伤害时，其获得所有“雨”；结束阶段，你与其获得各自的“雨”。",
}

local ryuuji = General(extension, "ev__ryuuji", "ev", 4)

local qingzhengyixin = fk.CreateActiveSkill{
  name = "qingzhengyixin",
  prompt = "#qingzhengyixin",
  anim_type = "drawcard",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
  end,
  target_num = 0,
  min_card_num = 0,
  card_filter = function(self, to_select)
    if not Self:prohibitDiscard(Fk:getCardById(to_select)) then
      return not table.contains(U.getMark(Self, "qingzhengyixin-turn"), Fk:getCardById(to_select):getTypeString())
    end
  end,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local cards = from:getCardIds("h")
    if table.every(cards, function (id) return Fk:getCardById(cards[1]).type == Fk:getCardById(id).type end) then
      from:showCards(cards)
      local to = room:askForChoosePlayers(from, table.map(room.alive_players, Util.IdMapper), 1, 1, "#qingzhengyixin-choose", self.name, false)
      if #to > 0 then
        room:getPlayerById(to[1]):drawCards(1, self.name)
      end
    elseif #effect.cards > 0 then
      room:throwCard(effect.cards, self.name, from, from)
      local mark = U.getMark(from, "qingzhengyixin-turn")
      for _, id in ipairs(effect.cards) do
        table.insertIfNeed(mark, Fk:getCardById(id):getTypeString())
      end
      room:setPlayerMark(from, "qingzhengyixin-turn", mark)
      if from:isAlive() then
        from:drawCards(#effect.cards, self.name)
        from:setSkillUseHistory(self.name, 0, Player.HistoryPhase)
      end
    end
  end,
}
ryuuji:addSkill(qingzhengyixin)
Fk:loadTranslationTable{
  ["ev__ryuuji"] = "高须龙儿",
  ["designer:ev__ryuuji"] = "烈火幽魂",
  ["qingzhengyixin"] = "清整一心",
  [":qingzhengyixin"] = "阶段技，若你的所有手牌类别：均相同，你可展示所有手牌，令一名角色摸一张牌；不均相同，你可弃置任意张牌（不得与本回合以此法弃置的牌类别相同），摸等量张牌并重置此技能。",
  ["#qingzhengyixin"] = "你可以选择任意张牌弃置，或不选牌展示所有手牌",
  ["#qingzhengyixin-choose"] = "请选择一名角色摸一张牌",
}

local yuzhuanjin = General(extension, "ev__yuzhuanjin", "ev", 3, 3, General.Female)

local ev__hushoujie = fk.CreateTriggerSkill{
  name = "ev__hushoujie",
  anim_type = "offensive",
  events = {fk.TurnEnd},
  derived_piles = {"hozen"},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and not EV.isFriend(player, target)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#ev__hushoujie::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".",
    }
    room:judge(judge)
    if #player:getPile("hozen") > 0 and table.find(player:getPile("hozen"), function(id) return Fk:getCardById(id).suit == judge.card.suit end) then
      if not target:isKongcheng() then
        local id = EV.askForCardChosen(room, player, target, "hs", self.name)
        room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
      end
    else
      player:addToPile("hozen", judge.card, true, self.name)
    end
  end,
}

local ev__pomojian = fk.CreateActiveSkill{
  name = "ev__pomojian",
  anim_type = "offensive",
  prompt = "#ev__pomojian",
  target_num = 1,
  card_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and #player:getPile("hozen") > 0 and table.find(Fk:currentRoom().alive_players, function(p)
      return self:withinTimesLimit(player, Player.HistoryPhase, Fk:cloneCard("ev_fire__slash"), "slash", p)
    end)
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id and
     U.canUseCardTo(Fk:currentRoom(), Self, Fk:currentRoom():getPlayerById(to_select), Fk:cloneCard("ev_fire__slash"), true, true)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:useVirtualCard("ev_fire__slash", player:getPile("hozen"), player, target, self.name, false)
    --room:addCardUseHistory("slash", 1)
  end,
}

local pomojian_buff = fk.CreateTriggerSkill{
  name = "#pomojian_buff",
  mute = true,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" and data.card.skillName == "ev__pomojian"
    and #data.card.subcards >= player.hp
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = data.to
    local n = math.min(#data.card.subcards, #to:getCardIds("he"))
    local cards = EV.askForCardsChosen(room, player, to, n, n, "hes", self.name)
    if #cards > 0 then
      room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
    end
  end,
}

ev__pomojian:addRelatedSkill(pomojian_buff)
yuzhuanjin:addSkill(ev__hushoujie)
yuzhuanjin:addSkill(ev__pomojian)

Fk:loadTranslationTable{
  ["ev__yuzhuanjin"] = "御馔津",
  ["designer:ev__yuzhuanjin"] = "次氯酸",
  ["ev__hushoujie"] = "狐狩界",
  [":ev__hushoujie"] = "一名角色的回合结束时，若其不为己方角色，你可判定，若你的角色牌上没有/有与结果花色相同的牌，你将此牌置于角色牌上，称为“符”/弃置其一张手牌。",
  ["#ev__hushoujie"] = "你可以对%dest发动“狐狩界”",
  ["hozen"] = "符",
  ["ev__pomojian"] = "破魔箭",
  [":ev__pomojian"] = "阶段技，你可将所有“符”当火【杀】使用，若之数量不小于你的体力值，则当此【杀】造成伤害时，你弃置受伤角色的等量张牌。",
  ["#ev__pomojian"] = "你可将所有“符”当火【杀】使用",
  ["#pomojian_buff"] = "破魔箭",
}
local heigushannv = General(extension, "ev__heigushannv", "ev", 4, 4, General.Female)

local buzhuozhiwang = fk.CreateViewAsSkill{
  name = "buzhuozhiwang",
  anim_type = "offensive",
  pattern = "thorn_circle",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("thorn_circle")
    card.skillName = self.name
    card:addSubcard(cards[1])
    return card
  end,
}

local buzhuozhiwang_prohibit = fk.CreateProhibitSkill{
  name = "#buzhuozhiwang_prohibit",
  is_prohibited = function(self, from, to, card)
    return card.skillName == "buzhuozhiwang" and card.trueName == "thorn_circle" and from:hasSkill(self) and to.chained
  end,
}

local buzhuozhiwang_trigger = fk.CreateTriggerSkill{
  name = "#buzhuozhiwang_trigger",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.BeforeChainStateChange},
  can_trigger = function(self, event, target, player, data)
    return target.chained and player:hasSkill(self.name) and player.phase ~= Player.NotActive and target ~= player
  end,
  on_use = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, "buzhuozhiwang", "control")
    return true
  end,
}

local zhangqichongyin = fk.CreateTriggerSkill{
  name = "zhangqichongyin",
  anim_type = "control",
  events = {fk.TargetSpecified, fk.AfterCardTargetDeclared},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) then
      if event == fk.TargetSpecified then
        return data.card.type == Card.TypeTrick and data.card.sub_type ~= Card.SubtypeDelayedTrick
      elseif data.card.type == Card.TypeBasic or data.card:isCommonTrick() then
        local cards = EV.getCenterArea(player.room)
        return #table.filter(cards, function(id) return Fk:getCardById(id).suit == Card.Spade end) > 0
        and #table.filter(cards, function(id) return Fk:getCardById(id).suit == Card.Club end) > 0
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TargetSpecified then
      return player.room:askForSkillInvoke(player, self.name, data, "#zhangqichongyin::"..data.to)
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      local judge = {
        who = player,
        reason = self.name,
        pattern = ".|.|club",
      }
      room:judge(judge)
      if judge.card.suit == Card.Club then
        room:loseHp(room:getPlayerById(data.to), 1, self.name)
      end
    else
      local targets = U.getUseExtraTargets(room, data, false)
      if #targets == 0 then return false end
      local tos = room:askForChoosePlayers(player, targets, 1, 1,
      "#zhangqichongyin-choose:::"..data.card:toLogString(), self.name, true)
      if #tos > 0 then
        table.forEach(tos, function (id) table.insert(data.tos, {id}) end)
      end
    end
  end,
}


buzhuozhiwang:addRelatedSkill(buzhuozhiwang_trigger)
buzhuozhiwang:addRelatedSkill(buzhuozhiwang_prohibit)
zhangqichongyin:addRelatedSkill(EV.center_area)
--EV.center_area
heigushannv:addSkill(buzhuozhiwang)
heigushannv:addSkill(zhangqichongyin)

Fk:loadTranslationTable{
  ["ev__heigushannv"] = "黑谷山女",
  ["designer:ev__heigushannv"] = "甜点吞噬者",
  ["buzhuozhiwang"] = "捕捉之网",
  [":buzhuozhiwang"] = "你可将一张黑色手牌当【荆棘之环】使用，且已横置的角色不是此牌的合法目标。其他角色于你的回合内重置前，你防止之。",
  ["#buzhuozhiwang_prohibit"] = "捕捉之网",
  ["#buzhuozhiwang_trigger"] = "捕捉之网",
  ["zhangqichongyin"] = "瘴气充溢",
  [":zhangqichongyin"] = "当你使用即时魔法牌指定一个目标后，你可判定，若结果为梅花，其失去1点体力。若于当前回合内置入弃牌堆的牌含有两种黑色花色，你使用的基础牌或即时魔法牌可额外选择一个目标。",
  ["#zhangqichongyin"] = "你可对%dest发动“瘴气充溢”",
  ["#zhangqichongyin-choose"] = "你可为%arg额外选择一个目标",
}

local leidianying = General(extension, "ev__leidianying", "ev", 4, 4, General.Female)
local yixinjingtu = fk.CreateTriggerSkill{
  name = "yixinjingtu",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.from ~= player.id
    and #table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 end) > 0
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player.room:getPlayerById(data.from), MarkEnum.UncompulsoryInvalidity .. "-turn")
    player.room:addPlayerMark(player.room:getPlayerById(data.from), "@@yixinjingtu-turn")
  end,
}

local yixinjingtu_effect = fk.CreateProhibitSkill{
  name = "#yixinjingtu_effect",
  prohibit_use = function(self, player, card)
    if player:hasSkill("yixinjingtu") and card then
      if card:isVirtual() then
        return table.find(card.subcards, function (id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 end)
      else
        return card:getMark("@@shown-inhand") > 0
      end
    end
  end,
}

local yixinjingtu_maxcards = fk.CreateMaxCardsSkill{
  name = "#yixinjingtu_maxcards",
  exclude_from = function(self, player, card)
    return player:hasSkill("yixinjingtu") and card:getMark("@@shown-inhand") > 0
  end,
}

local new_thunderSkill = fk.CreateActiveSkill{
  name = "new_thunder_skill",
  mute = true,
  target_num = 1,
  mod_target_filter = Util.TrueFunc,
  target_filter = Util.TrueFunc,
  on_effect = function(self, room, cardEffectEvent)
    local from = room:getPlayerById(cardEffectEvent.from)
    local to = room:getPlayerById(cardEffectEvent.to)
    local n = #table.filter(room.alive_players, function(p) return EV.isFriend(from, p) end)
    local cards = room:getNCards(n)
    local clubs = table.filter(cards, function(id) return Fk:getCardById(id).suit == Card.Club end)
    local spades = table.filter(cards, function(id) return Fk:getCardById(id).suit == Card.Spade end)
    room:moveCardTo(cards, Card.Processing, nil, fk.ReasonJustMove, "thunder_clap", nil, true, cardEffectEvent.to)
    room:delay(1200)
    for _, p in ipairs(room:getAlivePlayers(true)) do
      if EV.isFriend(from, p) then
        local ids, _ = U.askforChooseCardsAndChoice(from, cards, {"OK"}, "thunder_clap", "#new_thunder::"..p.id)
        room:moveCardTo(ids, Card.PlayerHand, p, fk.ReasonGive, "thunder_clap", "", true)
        table.removeOne(cards, ids[1])
      end
    end
    if #cards > 0 then
      room:moveCardTo(cards, Card.DrawPile, nil, fk.ReasonPut, "thunder_clap", nil, true, cardEffectEvent.to)
    end
    if #clubs > 0 then
      if not to:hasSkill("#thunder_clap_effect") then
        room:handleAddLoseSkills(to, "#thunder_clap_effect", nil, false, true)
      end
      room:setPlayerMark(to, "@@thunder_clap-turn", 1)
    end
    if #spades > 0 then
      room:damage({
        from = from,
        to = to,
        card = cardEffectEvent.card,
        damage = 1,
        damageType = fk.ThunderDamage,
        skillName = self.name
      })
    end
  end,
}

local mengxiangzhenshuo_trigger = fk.CreateTriggerSkill{
  name = "#mengxiangzhenshuo_trigger",
  mute = true,
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill("mengxiangzhenshuo") and data.from and data.card and EV.isFriend(player, target)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(target, self.name, nil, "#mengxiangzhenshuo_trigger::"..player.id)
  end,
  on_use = function(self, event, target, player, data)
    local card = player:drawCards(1, "mengxiangzhenshuo")
    EV.OpenCards(player.room, player, card, "mengxiangzhenshuo")
  end,

  refresh_events = {fk.PreCardEffect},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill("mengxiangzhenshuo") and data.from == player.id and data.card.trueName == "thunder_clap"
    and data.card.skillName == "mengxiangzhenshuo"
  end,
  on_refresh = function(self, event, target, player, data)
    local card = data.card:clone()
    local c = table.simpleClone(data.card)
    for k, v in pairs(c) do
      if card[k] == nil then
        card[k] = v
      end
    end
    card:addSubcards(data.card.subcards)
    card.skill = new_thunderSkill
    data.card = card
  end,
}

local mengxiangzhenshuo = fk.CreateActiveSkill{
  name = "mengxiangzhenshuo",
  anim_type = "offensive",
  prompt = "请选择己方角色数张明置手牌和一名角色",
  target_num = 1,
  card_num = function(self)
    return #table.filter(Fk:currentRoom().alive_players, function(p) return EV.isFriend(Self, p) end)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return Fk:getCardById(to_select):getMark("@@shown-inhand") > 0
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:moveCardTo(effect.cards, Card.DrawPile, nil, fk.ReasonPut, self.name, nil, true, effect.from)
    room:useVirtualCard("thunder_clap", nil, player, target, self.name, true)
  end,
}

Fk:addSkill(new_thunderSkill)
yixinjingtu:addRelatedSkill(yixinjingtu_effect)
yixinjingtu:addRelatedSkill(yixinjingtu_maxcards)
mengxiangzhenshuo:addRelatedSkill(mengxiangzhenshuo_trigger)
leidianying:addSkill(yixinjingtu)
leidianying:addSkill(mengxiangzhenshuo)

Fk:loadTranslationTable{
  ["ev__leidianying"] = "雷电影",
  ["designer:ev__leidianying"] = "zengyouyu",
  ["yixinjingtu"] = "一心净土",
  [":yixinjingtu"] = "锁定技，你不能使用明置手牌，你的明置手牌不计入手牌上限。当你成为其他角色使用牌的目标时，若你有明置手牌，则其非锁定技于当前回合内失效。",
  ["@@yixinjingtu-turn"] = "技能失效",
  ["#yixinjingtu_effect"] = "一心净土",
  ["mengxiangzhenshuo"] = "梦想真说",
  [":mengxiangzhenshuo"] = "阶段技，你可将X张明置手牌置于牌堆顶，视为使用【惊雷】；当你以此法展示牌堆顶的牌时改为展示X张牌，且交给每名己方角色其中的一张牌（X为己方角色数）。当己方角色使用牌造成伤害后，其令你摸一张牌并明置之。",
  ["#new_thunder"] = "请选择交给%dest的牌",
  ["#mengxiangzhenshuo_trigger"] = "你可以令%dest摸一张牌",
}

local darkmeta = General(extension, "ev__darkmeta", "ev", 4)

local fanjingfangyu = fk.CreateTriggerSkill{
  name = "fanjingfangyu",
  anim_type = "defensive",
  events = {fk.TargetSpecified, fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if event == fk.TargetSpecified then
      return player:hasSkill(self.name) and data.card.trueName == "slash" and target ~= player and not player:isKongcheng()
    else
      return player:hasSkill(self.name) and target == player and not player:isKongcheng()
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TargetSpecified then
      local unshown = table.filter(player:getCardIds(Player.Hand), function(id) 
        return Fk:getCardById(id):getMark("@@shown-inhand") == 0 and Fk:getCardById(id).suit == data.card.suit end)
      if #unshown > 0 then
        local cards = player.room:askForCard(player, 1, 1, false, self.name, true, tostring(Exppattern{ id = unshown }), "#fanjing-shown:::"..data.card:toLogString())
        if #cards > 0 then
          self.cost_data = cards[1]
          return true
        end
      end
    else
      local shown = table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 end)
      local n = data.damage
      if #shown > 0 then
        local cards = player.room:askForCard(player, n, n, false, self.name, true, tostring(Exppattern{ id = shown }), "#fanjing-discard:::"..n)
        if #cards > 0 then
          self.cost_data = cards
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      EV.OpenCards(room, player, self.cost_data, self.name)
    else
      room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
      return true
    end
  end,
}

local anfenshen_trigger = fk.CreateTriggerSkill{
  name = "#anfenshen_trigger",
  mute = true,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      local shown = table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 end)
      local unshown = table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
      return #shown >= #unshown and player:getMark("anfenshen-round") == 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "anfenshen-round")
    player.room:notifySkillInvoked(player, "anfenshen")
    --U.gainAnExtraTurn(player, true, self.name)
    player:gainAnExtraTurn(true)
    player.room:addPlayerMark(player, "anfenshen-buff")
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:getMark("anfenshen-buff") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "anfenshen-buff", 0)
    player.room:addPlayerMark(player, "@@anfenshen-turn")
  end,
}

local anfenshen_effect = fk.CreateProhibitSkill{
  name = "#anfenshen_effect",
  prohibit_use = function(self, player, card)
    if player:hasSkill("anfenshen") and player:getMark("@@anfenshen-turn") > 0 and Fk:currentRoom():getCardArea(card) == Card.PlayerHand then
      if card:isVirtual() then
        return table.find(card.subcards, function (id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
      else
        return card:getMark("@@shown-inhand") == 0
      end
    end
  end,
}

local anfenshen = fk.CreateViewAsSkill{
  name = "anfenshen",
  anim_type = "offensive",
  pattern = "ev__duel",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select):getMark("@@shown-inhand") > 0
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("ev__duel")
    card.skillName = self.name
    card:addSubcard(cards[1])
    return card
  end,
  enabled_at_play = function(self, player)
    return #table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 end) == 1
    and player:getMark("@@anfenshen-turn") > 0
  end,
  enabled_at_response = Util.FalseFunc,
}

anfenshen:addRelatedSkill(anfenshen_trigger)
anfenshen:addRelatedSkill(anfenshen_effect)
darkmeta:addSkill(fanjingfangyu)
darkmeta:addSkill(anfenshen)

Fk:loadTranslationTable{
  ["ev__darkmeta"] = "暗魅塔骑士",
  ["designer:ev__darkmeta"] = "路人orz",
  ["fanjingfangyu"] = "反镜防御",
  [":fanjingfangyu"] = "其他角色使用【杀】指定目标后，你可明置一张与此【杀】花色相同的手牌。当你受到伤害时，你可弃置与此伤害等量张明置手牌，防止此伤害。",
  ["#fanjing-shown"] = "你可明置一张与%arg花色相同的手牌",
  ["#fanjing-discard"] = "你可弃置%arg张明置手牌，防止此伤害",
  ["anfenshen"] = "暗分身",
  ["@@anfenshen-turn"] = "暗分身",
  ["#anfenshen_effect"] = "暗分身",
  [":anfenshen"] = "轮次技，回合结束后，若你的明置手牌不少于暗置手牌，你获得一个额外回合，且此回合内：你不能使用暗置手牌；若你的明置手牌仅有一张，你可将此牌当【决斗】使用。",
}

local yaodaoji = General(extension, "ev__yaodaoji", "ev", 4, 4, General.Female)

local qiongzhuibushe = fk.CreateTriggerSkill{
  name = "qiongzhuibushe",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart, fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.EventPhaseStart then
        return player.phase == Player.Start
      else
        local targets = table.filter(player.room.alive_players, function (p) return p:isWounded() end)
        return data.card.trueName == "slash" and #targets >= player.maxHp
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local targets = table.filter(room.alive_players, function (p) return not p:isWounded() end)
      if #targets > 0 then
        local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#qiongzhuibushe", self.name, false)
        if #to > 0 then
          room:damage({
            from = player,
            to = room:getPlayerById(to[1]),
            damage = 1,
            damageType = fk.NormalDamage,
            skillName = self.name,
          })
        end
      end
    else
      data.disresponsive = true
    end
  end,
}

local chiyingyishun = fk.CreateTriggerSkill{
  name = "chiyingyishun",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local room = player.room
      if event == fk.CardUsing then
        return target == player and data.card.trueName == "slash" and data.card.color == Card.Red
      else
        local events = room.logic:getEventsOfScope(GameEvent.Death, 1, function(e)
          local deathStruct = e.data[1]
          return deathStruct.damage and deathStruct.damage.from and deathStruct.damage.from == player
          and deathStruct.damage.card and deathStruct.damage.card.trueName == "slash" and deathStruct.damage.card.color == Card.Red
        end, Player.HistoryTurn)
        return #events > 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.CardUsing then
      data.additionalDamage = (data.additionalDamage or 0) + 1
    else
      --U.gainAnExtraTurn(player, true, self.name)
      player:gainAnExtraTurn(true)
    end
  end,
}

local qiongzhuibushe_tar = fk.CreateTargetModSkill{
  name = "#qiongzhuibushe_tar",
  bypass_distances = function(self, player, skill, card, to)
    if card and card.trueName == "slash" and player:hasSkill(self.name) then
      return #table.filter(Fk:currentRoom().alive_players, function (p) return p:isWounded() end) > player.hp
    end
  end,
}
qiongzhuibushe:addRelatedSkill(qiongzhuibushe_tar)
yaodaoji:addSkill(qiongzhuibushe)
yaodaoji:addSkill(chiyingyishun)

Fk:loadTranslationTable{
  ["ev__yaodaoji"] = "赤影妖刀姬",
  ["designer:ev__yaodaoji"] = "次氯酸",
  ["qiongzhuibushe"] = "穷追不舍",
  ["#qiongzhuibushe"] = "请选择一名未受伤的角色，对其造成1点伤害",
  [":qiongzhuibushe"] = "锁定技，准备阶段，你对一名未受伤的角色造成1点伤害。若已受伤的角色数不小于你的：体力值，你使用的【杀】无距离限制；体力上限，你使用的【杀】不是【闪】的合法目标。",
  ["chiyingyishun"] = "赤影一瞬",
  [":chiyingyishun"] = "锁定技，你使用红色【杀】造成的伤害+1。一名角色的回合结束后，若你于当前回合内使用红色【杀】杀死过角色，你获得一个额外回合。",
}

local cimutongzi = General(extension, "ev__cimutongzi", "ev", 4)

local diyuzhishou = fk.CreateTriggerSkill{
  name = "diyuzhishou",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(4)
    room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, "", "", true)
    if table.find(cards, function (id) return Fk:getCardById(id).trueName == "jink" end) then
      data.disresponsive = true
    end
  end,
}

local ev__qiannu = fk.CreateTriggerSkill{
  name = "ev__qiannu",
  anim_type = "offensive",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player.phase == Player.Play and target == player then
      local cards = EV.getCenterArea(player.room)
      local slashs = table.filter(cards, function (id) return Fk:getCardById(id).trueName == "slash" end)
      --local slashs = table.filter(cards, function (id) return Fk:getCardById(id).is_damage_card end)
      local num = 0
      player.room.logic:getEventsOfScope(GameEvent.ChangeHp, 999, function (e)
        local damage = e.data[5]
        if damage and player == damage.from then
          num = num + damage.damage
        end
      end, Player.HistoryPhase)
      self.cost_data = #slashs - num
      return #slashs > num
    end
  end,
  on_cost = function(self, event, target, player, data)
    local n = self.cost_data
    local targets = table.filter(player.room.alive_players, function (p) return p:getMark("qiannu_hurt-turn") == 0 end)
    local tos = player.room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), n, n, "#ev__qiannu:::"..n, self.name, true)
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(self.cost_data) do
      room:damage({
        from = player,
        to = room:getPlayerById(p),
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    end
  end,

  refresh_events = {fk.Damaged},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and player.phase ~= Player.NotActive and target:getMark("qiannu_hurt-turn") == 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(target, "qiannu_hurt-turn")
  end,

}

cimutongzi:addSkill(diyuzhishou)
cimutongzi:addSkill(ev__qiannu)

Fk:loadTranslationTable{
  ["ev__cimutongzi"] = "茨木童子",
  ["designer:ev__cimutongzi"] = "次氯酸",
  ["diyuzhishou"] = "地狱之手",
  [":diyuzhishou"] = "锁定技，当你使用【杀】指定一个目标后，你将牌堆顶的四张牌置入弃牌堆；若其中有【闪】，此【杀】不是【闪】的合法目标。",
  ["ev__qiannu"] = "迁怒",
  [":ev__qiannu"] = "出牌阶段结束时，若于本阶段内置入弃牌堆的【杀】的数量大于你于本阶段内造成过的伤害数，你可对X名于本回合内未受到过伤害的角色各造成1点伤害（X为二者之差）。",
  ["#ev__qiannu"] = "请选择%arg名此回合未受到伤害的角色",
}

local metaknight = General(extension, "ev__metaknight", "ev", 4)

local meitahuixuan = fk.CreateActiveSkill{
  name = "meitahuixuan",
  max_card_num = 1,
  max_target_num = 2,
  interaction = function()
    return UI.ComboBox {choices = {"meitahuixuan1", "meitahuixuan2"}}
  end,
  card_filter = function(self, to_select, selected)
    if self.interaction.data == "meitahuixuan2" then
      local card = Fk:cloneCard("ev__slash")
      return Fk:getCardById(to_select):getMark("@@shown-inhand") > 0 and U.canUseCard(Fk:currentRoom(), Self, card, true)
    else
      return false
    end
  end,
  target_filter = function(self, to_select, selected)
    if self.interaction.data == "meitahuixuan2" then
      local card = Fk:cloneCard("ev__slash")
      return U.canUseCardTo(Fk:currentRoom(), Self, Fk:currentRoom():getPlayerById(to_select), card, true, true) and #selected < 2
    else
      return false
    end
  end,
  feasible = function(self, selected, selected_cards)
    if self.interaction.data == "meitahuixuan2" then
      return #selected_cards == 1 and #selected > 0
    end
    return #selected_cards == 0 and #selected == 0
  end,
  can_use = function(self, player)
    return player:getMark("meitahuixuan-turn") == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    if self.interaction.data == "meitahuixuan1" then
      player:drawCards(1, self.name)
      local unshown = table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
      if #unshown > 0 then
        local cards = room:askForCard(player, 1, 1, false, self.name, false, tostring(Exppattern{ id = unshown }), "#meitahuixuan")
        if #cards > 0 then
          EV.OpenCards(room, player, cards, self.name)
        end
      end
      room:addPlayerMark(player, "meitahuixuan-turn")
    else
      local targets = table.map(effect.tos, Util.Id2PlayerMapper)
      room:useVirtualCard("ev__slash", effect.cards, player, targets, self.name, false)
    end
  end,
}

local yinhefanji = fk.CreateTriggerSkill{
  name = "yinhefanji",
  anim_type = "defensive",
  events = {fk.TargetConfirming, fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if event == fk.TargetConfirming then
      return player:hasSkill(self.name) and data.card.trueName == "slash" and EV.isFriend(player, target) and player:usedSkillTimes(self.name) == 0
      and #table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end) > 0
    else
      return player:hasSkill(self.name) and data.card.trueName == "slash" and data.card:getMark("yinhefanji_buff") ~= 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TargetConfirming then
      return player.room:askForSkillInvoke(player, self.name, nil, "#yinhefanji::"..data.from)
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirming then
      local from = room:getPlayerById(data.from)
      local id = EV.askForCardChosen(room, from, player, "h", self.name)
      if id > 0 then
        EV.OpenCards(room, player, id, self.name, from)
        local card = Fk:getCardById(id)
        if card.trueName == "slash" then
          room:setCardMark(data.card, "yinhefanji_buff", data.from)
        else
          player.room:doIndicate(target.id, { player.id })
          TargetGroup:removeTarget(data.targetGroup, target.id)
          TargetGroup:pushTargets(data.targetGroup, player.id)
        end
      end
    else
      if target.id == data.card:getMark("yinhefanji_buff") then
        room:useVirtualCard("ev__duel", nil, player, target, self.name, false)
      end
      room:setCardMark(data.card, "yinhefanji_buff", 0)
    end
  end,
}

metaknight:addSkill(meitahuixuan)
metaknight:addSkill(yinhefanji)

Fk:loadTranslationTable{
  ["ev__metaknight"] = "魅塔骑士",
  ["designer:ev__metaknight"] = "路人orz",
  ["meitahuixuan"] = "魅塔回旋斩",
  [":meitahuixuan"] = "出牌阶段，你可选择一项：1.摸一张牌并明置一张手牌，然后此技能于本回合内失效；2.将一张明置手牌当【杀】使用，此【杀】可额外选择一个目标。",
  ["meitahuixuan1"] = "摸一张牌并明置一张手牌",
  ["meitahuixuan2"] = "将一张明置手牌当【杀】使用",
  ["#meitahuixuan"] = "请明置一张手牌",
  ["yinhefanji"] = "银河反击",
  ["#yinhefanji"] = "银河反击：你可令%dest明置你的一张手牌",
  [":yinhefanji"] = "回合技，当己方角色成为其他角色使用【杀】的目标时，你可令此【杀】的使用者明置你的一张手牌，若此牌：为【杀】，当其使用的此【杀】结算结束后，你视为对其使用【决斗】；不为【杀】，其将此【杀】转移给你。",
}

return extension